﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbSystemDal
	{
		public DbSystemDal()
		{
		}
 		#region Insert
 		public static int Insert(DbSystem dbSystem)
		{	
			string sql = @"Insert Into DbSystem (
					SWebName,
					STitle,
					SKeywords,
					SDescription,
					SIcon,
					SLogo,
					SContactName,
					SWeb400,
					SWebUrl,
					SAddress,
					SEmail,
					SBottom,
					SEditTime,
					SIsUrlReWrite,
					SWebStatus,
					SWebStopAlter,
					SDefaultPayId,
					SDefaultPayName,
					SIfBackMusic,
					SBackMusicPath,
					WeChat,
					Weibo,BaoMingState
				) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}',{13},{14},'{15}','{16}','{17}',{18},'{19}','{20}','{21}',{22})";
			sql = string.Format(sql,
					SqlHelper.String(dbSystem.SWebName),
					dbSystem.STitle,
					dbSystem.SKeywords,
					dbSystem.SDescription,
					SqlHelper.String(dbSystem.SIcon),
					SqlHelper.String(dbSystem.SLogo),
					SqlHelper.String(dbSystem.SContactName),
					SqlHelper.String(dbSystem.SWeb400),
					SqlHelper.String(dbSystem.SWebUrl),
					SqlHelper.String(dbSystem.SAddress),
					SqlHelper.String(dbSystem.SEmail),
					dbSystem.SBottom,
					dbSystem.SEditTime,
					dbSystem.SIsUrlReWrite,
					dbSystem.SWebStatus,
					dbSystem.SWebStopAlter,
					SqlHelper.String(dbSystem.SDefaultPayId),
					SqlHelper.String(dbSystem.SDefaultPayName),
					dbSystem.SIfBackMusic,
					SqlHelper.String(dbSystem.SBackMusicPath),
					SqlHelper.String(dbSystem.WeChat),
					SqlHelper.String(dbSystem.Weibo),
                    dbSystem.BaoMingState
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbSystem dbSystem)
		{	
			string sql = @"Update DbSystem set 

					SWebName= '{0}',
					STitle= '{1}',
					SKeywords= '{2}',
					SDescription= '{3}',
					SIcon= '{4}',
					SLogo= '{5}',
					SContactName= '{6}',
					SWeb400= '{7}',
					SWebUrl= '{8}',
					SAddress= '{9}',
					SEmail= '{10}',
					SBottom= '{11}',
					SEditTime= '{12}',
					SIsUrlReWrite= {13},
					SWebStatus= {14},
					SWebStopAlter= '{15}',
					SDefaultPayId= '{16}',
					SDefaultPayName= '{17}',
					SIfBackMusic= {18},
					SBackMusicPath= '{19}',
					WeChat= '{20}',
					Weibo= '{21}',
                    BaoMingState={22}
				where

					SId= {23}";
			sql = string.Format(sql,
					SqlHelper.String(dbSystem.SWebName),
					dbSystem.STitle,
					dbSystem.SKeywords,
					dbSystem.SDescription,
					SqlHelper.String(dbSystem.SIcon),
					SqlHelper.String(dbSystem.SLogo),
					SqlHelper.String(dbSystem.SContactName),
					SqlHelper.String(dbSystem.SWeb400),
					SqlHelper.String(dbSystem.SWebUrl),
					SqlHelper.String(dbSystem.SAddress),
					SqlHelper.String(dbSystem.SEmail),
					dbSystem.SBottom,
					dbSystem.SEditTime,
					dbSystem.SIsUrlReWrite,
					dbSystem.SWebStatus,
					dbSystem.SWebStopAlter,
					SqlHelper.String(dbSystem.SDefaultPayId),
					SqlHelper.String(dbSystem.SDefaultPayName),
					dbSystem.SIfBackMusic,
					SqlHelper.String(dbSystem.SBackMusicPath),
					SqlHelper.String(dbSystem.WeChat),
					SqlHelper.String(dbSystem.Weibo),
                    dbSystem.BaoMingState,
					dbSystem.SId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 sId)
		{
		
			string sql = @"Delete from DbSystem where 
					SId= {0}";
			sql = string.Format(sql,
					sId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbSystem a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbSystem Select(Int32 sId)
		{
			DbSystem dbSystem = null;
			string sql = @"select a.* from DbSystem a  where
					a.SId= {0}
";
			sql = string.Format(sql,
					sId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbSystem = new DbSystem(ds.Tables[0].Rows[0]);					
			return dbSystem;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbSystem a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbSystem a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbSystem a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
